package com.personal.Visualplan.controller;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.personal.Visualplan.entity.Tag;
import com.personal.Visualplan.service.TagService;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/tag")
public class TagOperatController {

	@Resource
	private TagService tagService;
	
	@RequestMapping("/addTag")
	public String addTag() {
		String name = "helloWorld!-1";
		Tag tag = new Tag();
		tag.setName(name);
		return tagService.addTag(tag).toString();
	}
	
	@RequestMapping("/findById")
	public String findTagById() {
		int id = 1;
		return tagService.findTagById(id).toString();
	}
	
	@RequestMapping("/findByName")
	public String findTagByName() {
		String name = "helloWorld!";
		return tagService.findTagByName(name).toString();
	}
	
	@RequestMapping("/findAll")
	public String findAll() {
		List<Tag> tagList = new ArrayList<Tag>();
		tagList=tagService.getAllTags();
		StringBuilder resultBuilder = new StringBuilder(); 
		for(int i = 0;i<tagList.size();i++) {
			resultBuilder.append(tagList.get(i).toString());
		}
		return resultBuilder.toString();
	}
}
